package com.ruoyi.dmsIms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dmsIms.domain.TestDocument;
import com.ruoyi.dmsIms.service.ITestDocumentService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 测试文档Controller
 * 
 * @author ZhangSiRui
 * @date 2022-01-14
 */
@RestController
@RequestMapping("/dmsIms/document")
public class TestDocumentController extends BaseController
{
    @Autowired
    private ITestDocumentService testDocumentService;

    /**
     * 查询测试文档列表
     */
//    @PreAuthorize("@ss.hasPermi('dmsIms:document:list')")
    @GetMapping("/list")
    public TableDataInfo list(TestDocument testDocument)
    {
        startPage();
        List<TestDocument> list = testDocumentService.selectTestDocumentList(testDocument);
        return getDataTable(list);
    }

    /**
     * 查询测试文档列表
     */
    @GetMapping("/doclist/{noteId}")
    public TableDataInfo list(@PathVariable("noteId") Long noteId)
    {
        List<TestDocument> list = testDocumentService.selectTestNoteDocmentList(noteId);
        return getDataTable(list);
    }

    /**
     * 导出测试文档列表
     */
    @PreAuthorize("@ss.hasPermi('dmsIms:document:export')")
    @Log(title = "测试文档", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TestDocument testDocument)
    {
        List<TestDocument> list = testDocumentService.selectTestDocumentList(testDocument);
        ExcelUtil<TestDocument> util = new ExcelUtil<TestDocument>(TestDocument.class);
        util.exportExcel(response, list, "测试文档数据");
    }

    /**
     * 获取测试文档详细信息
     */
//    @PreAuthorize("@ss.hasPermi('dmsIms:document:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(testDocumentService.selectTestDocumentById(id));
    }

    /**
     * 新增测试文档
     */
//    @PreAuthorize("@ss.hasPermi('dmsIms:document:add')")
    @Log(title = "测试文档", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TestDocument testDocument)
    {
        testDocumentService.insertTestDocument(testDocument);
        Long docId = testDocument.getId();
        return AjaxResult.success(docId);
    }

    /**
     * 修改测试文档
     */
//    @PreAuthorize("@ss.hasPermi('dmsIms:document:edit')")
    @Log(title = "测试文档", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TestDocument testDocument)
    {
        return toAjax(testDocumentService.updateTestDocument(testDocument));
    }

    /**
     * 删除测试文档
     */
//    @PreAuthorize("@ss.hasPermi('dmsIms:document:remove')")
    @Log(title = "测试文档", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(testDocumentService.deleteTestDocumentByIds(ids));
    }
}
